using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class InputOutputParameterPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if(txtEmail.Text!="" && chkAgree.Checked)
        {
            
            if (Session["rcuserid"] == null)
            {                        
                SqlDataSource sqlDataSource= new SqlDataSource();
                sqlDataSource.ConnectionString =
                WebConfigurationManager.ConnectionStrings[
                "RecruitVietnamDbConnectionString"
                ].ConnectionString;
                sqlDataSource.InsertCommand="SPRCAccount"; 
                sqlDataSource.InsertCommandType= 
                SqlDataSourceCommandType.StoredProcedure;
                Parameter parameter = new
                Parameter("Email",                 
                TypeCode.String, txtEmail.Text);
                sqlDataSource.InsertParameters.Add(parameter);

                parameter = new
                        Parameter("Password",
                        TypeCode.String,  txtPassword.Text);
                sqlDataSource.InsertParameters.Add(parameter);

                parameter = new
                       Parameter("CompanyName",
                       TypeCode.String,  txtCompanyName.Text);
                sqlDataSource.InsertParameters.Add(parameter);
                     
                parameter = new
                Parameter("EnglishName",
                TypeCode.String,  txtEnglishName.Text);
                sqlDataSource.InsertParameters.Add(parameter);
                
                parameter = new
                Parameter("NewsLetter",
                TypeCode.String, ((chkNewsLetter.Checked) ? "1" : "0"));
                sqlDataSource.InsertParameters.Add(parameter);
                
                parameter = new
                Parameter("ResumeAlert",
                TypeCode.String, ((chkResumeAlert.Checked) ? "1" : "0"));
                sqlDataSource.InsertParameters.Add(parameter);
                
                parameter = new
                Parameter("Promotion",
                TypeCode.String, ((chkPromotion.Checked) ? "1" : "0"));
                sqlDataSource.InsertParameters.Add(parameter);

                Parameter parameterInputOutput = new
                Parameter("RecruiterID",                 
                TypeCode.Int32, "0");
                parameterInputOutput.Direction = ParameterDirection.InputOutput;
                
                sqlDataSource.InsertParameters.Add(parameterInputOutput);
                sqlDataSource.Insert();
                
                string userID = parameterInputOutput.DefaultValue;
                                
                if(userID=="0")
                {
                    literalError.Text=
                    "Sorry! RCV database show that "+
                    "someone has registered a recruiter "+
                    "account with this e-mail "+
                    "address. If you have previously "+
                    "registered under this e-mail "+
                    "address and forgotten your "+
                    "password, you can request for "+
                    "your password <a href=\""+
                    "forgotpassword.aspx\">here</a>";
                }
               
                else               
                {
                    Session.Add("rcuserid", userID);
                    Session.Add("rcemail", txtEmail.Text);
                    Session.Add("rccompanyname", 
                    txtCompanyName.Text + " " + txtEnglishName.Text);
                    literalError.Text = "";
                                        
                    Response.Redirect("contact.aspx");                   
                }
            }
            else
            {
                literalError.Text = "Updated successfull";

                Session.Add("rcfullname", txtCompanyName.Text + " " + txtEnglishName.Text);
            }
        }
        else
        {
            literalError.Text = "Please check on Agree checkbox";
           
        }
    }
}
